package main

import (
	"fmt"
	"github.com/prometheus/client_golang/prometheus/promhttp"
	"go-prometheus/metric"
	"io/ioutil"
	"log"
	"net/http"
	"os"
	"time"
)

type User struct {
}

func (this User) A() string {
	return "A"
}

func (this *User) B() string {
	return "B"
}

func main() {
	go func() {
		for {
			ioutil.WriteFile("./test.txt", []byte(time.Now().String()), os.ModePerm)
			time.Sleep(1 * time.Second)
		}

	}()

	go func() {
		fmt.Println("aaa")

	}()

	time.Sleep(30 * time.Second)
}

func test() (err error) {
	fmt.Printf("%p\n", &err)
	a, err := testb()
	fmt.Printf("%p\n", &err)

	if _, err := testb(); err != nil {
		fmt.Printf("%p\n", &err)
	}

	if err != nil {
		return
	}
	a = a
	return

}

func testb() (a string, err error) {
	err = fmt.Errorf("aaa")
	return "", err
}

func metricF() {

	counterVec := metric.NewCounterVec(&metric.CounterVecOpts{
		Name:   "exec_sql",
		Help:   "http client requests error count.",
		Labels: []string{"sql", "param"},
	})
	//
	histogramVec := metric.NewHistogramVec(&metric.HistogramVecOpts{
		Name:    "counts_test",
		Help:    "rpc server requests duration(ms).",
		Buckets: []float64{1, 5, 10, 15},
		Labels:  []string{"method"},
	})

	go func() {
		for {
			time.Sleep(1 * time.Second)
			counterVec.Inc("/Users", "500")
			histogramVec.Observe(2, "/Users")
			histogramVec.Observe(8, "/Users")

		}

	}()

	fmt.Println("进程Id", os.Getppid())

	http.Handle("/metrics", promhttp.Handler())
	log.Fatal(http.ListenAndServe(":8080", nil))

}
